#include <iostream>

using namespace std;

bool putAble(char map[4][4], int x, int y)
{
	if(map[y][x] == 'X')
		return false;

	for(int i = x - 1;i >= 0;i --)
	{
		if(map[y][i] == 'X')
			break;
		if(map[y][i] == 'F')
			return false;
	}

	for(int i = y - 1;i >= 0;i --)
	{
		if(map[i][x] == 'X')
			break;
		if(map[i][x] == 'F')
			return false;
	}
	return true;
}

void dfs(char map[4][4], int n, int val, int x, int y, int &max)
{
	if(val > max)
		max = val;

	if(x >= n || y >= n)
		return;

	if(putAble(map, x, y))
	{
		map[y][x] = 'F';
		val ++;
		if(x < n - 1)
		{
			dfs(map, n, val, x + 1, y, max);
		}
		else
		{
			dfs(map, n, val, 0, y + 1, max);
		}
		val --;
		map[y][x] = '.';
	}

	if(x < n - 1)
	{
		dfs(map, n, val, x + 1, y, max);
	}
	else
	{
		dfs(map, n, val, 0, y + 1, max);
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	char map[4][4];
	int n;
	int max = 0;
	cin >> n;
	while(n)
	{
		for(int i = 0;i < n;i ++)
		{
			for(int j = 0;j < n;j ++)
			{
				cin >> map[i][j];
			}
		}
		
		dfs(map, n, 0, 0, 0, max);

		cout << max << endl;

		max = 0;
		cin >> n;
	}
	return 0;
}